package com.martian.controller;

import com.martian.common.exception.SysException;
import com.martian.common.exception.UserException;
import com.martian.common.wrapper.ResultWrapper;
import com.martian.pojo.form.ManagerLoginForm;
import com.martian.pojo.form.UserLoginForm;
import com.martian.pojo.form.UserRegisterForm;
import com.martian.service.ManagerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author martian
 * @version V1.0.0
 * @Description
 * @date 2023-04-16 15:04
 */
@CrossOrigin
@Api(value = "ManagerController", tags = {"管理员API"})
@RestController
@RequestMapping("/manager")
public class ManagerController {
    @Resource
    ManagerService managerService;

    @ApiOperation(value = "管理员登录", produces = "application/json")
    @PostMapping("/visitor/managerLogin")
    public ResultWrapper userLogin(@RequestBody ManagerLoginForm managerLoginForm){
        try {
            return ResultWrapper.successWithData(managerService.managerLogin(managerLoginForm));
        }catch (SysException e){
            return ResultWrapper.failure(e.getMessage());
        }
    }
    @ApiOperation(value = "用户注册",produces = "application/json")
    @PostMapping("/visitor/userRegister")
    public ResultWrapper userRegister(@RequestBody UserRegisterForm userRegisterForm){
        try{
            boolean isOk = managerService.userRegister(userRegisterForm);
            return ResultWrapper.success("注册成功");
        }catch (UserException e){
            return ResultWrapper.failure(e.getMessage());
        }
    }
    @ApiOperation(value = "覆盖率指标",produces = "application/json")
    @PostMapping("/coverage")
    public ResultWrapper coverageMetric(){
        try{
            return ResultWrapper.successWithData(managerService.coverageMetric());
//            return ResultWrapper.successWithData(managerService.coverageMetric());
        }catch (UserException e){
            return ResultWrapper.failure(e.getMessage());
        }
    }
}
